package com.example.service;

import com.example.mapper.JobRecruiterMapper;
import com.example.mapper.PostMapper;
import com.example.pojo.bo.HomeCompanyBO;
import com.example.pojo.bo.HomePosterBO;
import com.example.pojo.dto.HomeCompanyDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 本文来演示
 *
 * @author 赵建云
 * @create 2023/10/9
 */
@Service
public class HomeCompanyServiceImpl implements HomeCompanyService{
    @Autowired
    private JobRecruiterMapper jobRecruiterMapper;
    @Autowired
    private PostMapper postMapper;

    @Override
    public List<HomeCompanyDTO> findCompany() {
        List<HomeCompanyDTO> list = new ArrayList<>();
        List<HomeCompanyBO> homeCompanyBO = jobRecruiterMapper.findCompanyAll();
        for (HomeCompanyBO companyBO : homeCompanyBO) {
            Integer id = companyBO.getId();
            HomePosterBO homePosterBO = postMapper.findById(id);
            HomeCompanyDTO homeCompanyDTO = new HomeCompanyDTO();
            homeCompanyDTO.setId(id);
            homeCompanyDTO.setCompanyName(companyBO.getCompanyName());
            homeCompanyDTO.setCompanyType(companyBO.getCompanyType());
            if (companyBO.getEmployeesQuantity()>0&&companyBO.getEmployeesQuantity()<=100){
                homeCompanyDTO.setEmployeesQuantity("0-100人");
            } else if (companyBO.getEmployeesQuantity()>100&&companyBO.getEmployeesQuantity()<1000) {
                homeCompanyDTO.setEmployeesQuantity("100-1000人");
            }else if (companyBO.getEmployeesQuantity()>1000&&companyBO.getEmployeesQuantity()<10000){
                homeCompanyDTO.setEmployeesQuantity("1000-10000人");
            }else {
                homeCompanyDTO.setEmployeesQuantity("10000人以上");
            }
            if (homePosterBO!=null&&homePosterBO.getPayFloor()>=1000){
                homeCompanyDTO.setPay(homePosterBO.getPayFloor()/1000+"-"+ homePosterBO.getPayUpper()/1000+"k");
            }else if (homePosterBO!=null){
                homeCompanyDTO.setPay(homePosterBO.getPayFloor()+"-"+homePosterBO.getPayUpper()+"元");
            }
            homeCompanyDTO.setPosName(homePosterBO.getPosName());
            homeCompanyDTO.setJrAvatar(companyBO.getJrAvatar());
            if (companyBO.getRunState()==0){
                homeCompanyDTO.setRunState("未上市");
            }else {
                homeCompanyDTO.setRunState("已上市");
            }
            list.add(homeCompanyDTO);

        }
        return list;
    }
}
